Lab 12: Create Public S3 Bucket Using Terraform
As part of the data migration process, the Nautilus DevOps team is actively creating several S3 buckets on AWS. They plan to utilize both private and public S3 buckets to store the relevant data. Given the ongoing migration of other infrastructure to AWS, it is logical to consolidate data storage within the AWS environment as well.
-
Create a
publicS3 bucket nameddatacenter-s3-24526using Terraform. -
Ensure the bucket is accessible publicly once created by setting the proper ACL.
The Terraform working directory is
/home/bob/terraform. Create themain.tffile (do not create a different.tffile) to accomplish this task.
Notes:
- Create the resources only in the
us-east-1region. - Right-click under the
EXPLORERsection inVS Codeand selectOpen in Integrated Terminalto launch the terminal. - The name of the S3 bucket should be based on
datacenter-s3-24526. - You can use the
ACLsettings to ensure the bucket is publicly accessible.
Create main.tf
resource "aws_s3_bucket" "datacenter-s3-24526" {
bucket = "datacenter-s3-24526"
tags = {
Name = "datacenter-s3-24526"
}
}
resource "aws_s3_bucket_public_access_block" "datacenter-s3-24526" {
bucket = aws_s3_bucket.datacenter-s3-24526.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
resource "aws_s3_bucket_acl" "datacenter-s3-24526" {
depends_on = [
aws_s3_bucket_public_access_block.datacenter-s3-24526
]
bucket = aws_s3_bucket.datacenter-s3-24526.id
acl = "public-read"
}
terraform init
terraform plan -out kke.plan && terraform apply kke.plan
# or apply forcefully without creating plan and applying it
terraform apply -auto-approve
aws s3 ls
aws s3api get-public-access-block --bucket devops-s3-30445